package com.heeexy.example.controller.web;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.heeexy.example.service.NewsService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import yinwei.bo.common.entry.news;
import yinwei.bo.common.result.R;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("news")
public class NewsController {

    @Resource
    private NewsService newsService;

    @RequestMapping("/findNews")
    public R findNews(@RequestParam(defaultValue = "1") Integer CurrentPage,
            @RequestParam(defaultValue = "5") Integer PageSize){
        List<news> list=newsService.findNews();
        PageHelper.offsetPage((CurrentPage - 1) * PageSize,PageSize);
        PageInfo pageInfo = new PageInfo(list);
        Map map=new HashMap();
        map.put("list",pageInfo);
        return R.ok().data(map);
    }

    @RequestMapping(value = "/getByNewsId",method = RequestMethod.GET)
    public R findByNewsId(Integer id){
        System.out.println(id);
        news news=newsService.findByNewsId(id);
        Map map = new HashMap();
        map.put("news",news);
        return R.ok().data(map);
    }

}
